package org.jflame.commons.crypto;

import java.security.KeyPair;
import java.security.spec.ECGenParameterSpec;

/**
 * SM2非对称加密工具类,使用java jce方式调用.基于bcprov-jdk15on(&gt;1.61) <br>
 * BouncyCastleProvider中的SM2Engine#Mode默认是旧标准C1C2C3,JCE方式调用无法切换. 需要切换模式请使用 {@link SM2Encryptor}
 */
public class SM2JCEEncryptor extends AsymmetricEncryptor {

    public SM2JCEEncryptor() throws EncryptException {
        super(Transformation.SM2_NONE_NOPADDING, "BC");
    }

    /**
     * SM2算法生成密钥对
     *
     * @return 密钥对信息
     * @throws EncryptException
     */
    public KeyPair generateKeyPair() throws EncryptException {
        return KeyUtils.generateKeyPair("EC", new ECGenParameterSpec("sm2p256v1"), "BC");
    }

    @Override
    public boolean isSupport() {
        return transformation.getAlg() == Alg.SM2;
    }

}
